/*
   Copyright 2009 Abdulla Abdurakhmanov (abdulla@latestbit.com)
   Original sources are available at www.latestbit.com

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package org.latestbit.smartobjects;

import java.util.UUID;

import org.latestbit.smartobjects.exceptions.SmartBusSystemException;
import org.latestbit.smartobjects.testmodel.*;

public class SimpleInterfaceFactorySyncServer implements ISimpleFactorySyncSmartObject {
	private String sessionId = UUID.randomUUID().toString();

	@Override
	public SimpleInterfaceSkeleton createSimpleInterface( ) throws SmartBusSystemException {
		SimpleInterfaceSyncSkeleton skeleton = new SimpleInterfaceSyncSkeleton ( new SimpleInterfaceSyncServer() );
		return skeleton;
	}	

	@Override
	public String putSimpleInterface(ISimpleInterface intf) throws SmartBusSystemException {
		try {
			return intf.helloWorld("World");
		}
		catch(Exception ex) {
			throw new SmartBusSystemException(ex);
		}
	}
	
	@Override
	public String createSimpleSession()
			throws SmartBusSystemException {
		return getSessionId();
	}	

	@Override
	public void continueSession(String id)
			throws SmartBusSystemException {
		this.setSessionId(id);
	}	
	
	@Override
	public void destroy() {
	}

	public void setSessionId(String sessionId) {
		this.sessionId = sessionId;
	}

	public String getSessionId() {
		return sessionId;
	}	
}
